<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.store.TaskMgr"%>
<%@page import="com.store.Task"%>
<%@page import="com.tss.util.*"%>
<%@page import="com.store.*"%>
<%@page import="com.jedi.*"%>
<%@include file="../global_var.jsp"%>
<%@page import="java.text.*"%>
<%@include file="../check_login.jsp"%>
<%
	UserMgr userMgr = new UserMgr();
	List userList=null;
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String enddate = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
Calendar calen = Calendar.getInstance();
calen.setTime(TSSDate.parseDate(enddate));
calen.add(Calendar.MONTH, -1);
String begindate = new SimpleDateFormat("yyyy-MM-dd").format(calen.getTime());
User just_user = (User)session.getAttribute("LoginUser");
String power_enable_id = "10201";
String power1_enable_id = "10211";
if (!just_user.hasPower(power_enable_id)&& !just_user.hasPower(power1_enable_id)) {
	out.println(strNoPowerInfo); 
	return;
}
TaskMgr taskMgr = new TaskMgr();
String engineerid     = ParamUtils.getParameter(request,"engineerid","");
String techmanager     = ParamUtils.getParameter(request,"techmanager","");
List list = null;
String area_id       = ParamUtils.getParameter(request,"area_id","");
String begin_date    = ParamUtils.getParameter(request,"begin_date",begindate);
String end_date      = ParamUtils.getParameter(request,"end_date",enddate);
String time_type     = ParamUtils.getParameter(request,"time_type","1");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'borrow_list.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
	<link href="style/main.css" rel="stylesheet" type="text/css">
		<script language="javascript" src="js/common.js"></script>
<script language="javascript">


function clk_task_select(strID,engineerid,engineername,custemer) {
	top.returnValue = strID+ "," +engineerid+ "," +engineername+ "," +custemer;
	top.close();
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="99%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
	 <td >
		<form name="pageForm" method="post">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td height="100" valign="top" align="center" style="padding-top:12px;padding-bottom:10px;">
								
					<table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
					<tr bgcolor="#D7D7DB">
						<td height="25" >
			      所属区域：
                  <select name="area_id" onchange="pageForm.submit();" style="width:60px">
                    <option value="">全部</option>
                    <%for(int i=0;i<area_item_info.length;i++){%>
                    <option value="<%=area_item_info[i]%>"<%if (area_id.equals(area_item_info[i])){%> selected<%}%>><%=area_item_info[i]%></option>
                    <%}%>
                  </select>
               
            	       <%
                  	if(just_user.hasPower(power1_enable_id)){	%>
                 
            	        工程师：
                    <select name="engineerid"  style="width:60px" >
            	        <option value="">全部</option>
            	        <%
            	    	String engineer="engineer";
            	    
            	         userList = userMgr.getUsersGroupbyroleid(engineer);
            	        if (userList != null && userList.size() > 0) {
                    		for(int i=0;i<userList.size();i++){
                    			User item = (User)userList.get(i);
                    	%>
                        <option value="<%=item.getId()%>"<%if (item.getId().equals(engineerid)) {%> selected<%}%>><%=item.getUserName()%></option>
                    	<%}}%>
            	      </select>
            	      <%}%>
            	      
             登记日期：
              
                  从 <span id="htmlBeginTime">&nbsp;</span> &nbsp; 至 &nbsp; <span id="htmlEndTime" >&nbsp;</span>
                
                  <input type="submit" class="inputButton" value="确定">
						
				</td>
			</tr>
			 <tr bgcolor="#FFFFFF">
					<td height="15" style="padding-left:10px;" colspan="4">
					</td>
					</tr>
			</table>
            <table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
              <tr align="center" bgcolor="#858585">
                <td width="12%" height="24"><font color="#FFFFFF">客户名称</font></td>
                <td width="6%" height="24"><font color="#FFFFFF">联系人</font></td>
                
                 <td width="6%"><font color="#FFFFFF">项目经理</font></td>
                <td width="6%"><font color="#FFFFFF">工程师</font></td>
                <td width="7%"><font color="#FFFFFF">差旅费</font></td>
                <td width="7%"><font color="#FFFFFF">服务开始时间</font></td>
               <td width="7%"><font color="#FFFFFF">服务结束时间</font></td>
    
          
                <td width="5%"><font color="#FFFFFF">操作</font></td>
              </tr>
              <%
              String otherSQL = "and  engineerid='"+just_user.getId()+"'";
            
      
             if(just_user.hasPower(power1_enable_id)){
                		otherSQL="";
                }
                else if(just_user.hasPower(power_enable_id)){
				 			if(just_user.getRoleId().trim().equals(pm_role_id)){
				 			
				 			otherSQL=" and tc.techmanager ='"+just_user.getId()+"'";
				 			
				 			
				 			}else 	if(just_user.getRoleId().trim().equals(engineer_role_id)){
					  
				             otherSQL=" and engineerid='"+just_user.getId().trim()+"'";
				             }else   otherSQL=" and engineerid='"+just_user.getId().trim()+"'";
				       
				  }
               
        
          if (!area_id.trim().equals("")) otherSQL += " and t.area_id like '%" + area_id.trim() + "%'";
          if (!engineerid.trim().equals("")) otherSQL += " and engineerid = '" + engineerid + "'";
          if (!techmanager.trim().equals("")) otherSQL += " and tc.techmanager = '" + techmanager + "'";
	       if (!begin_date.trim().equals("")) otherSQL += " and substring(t.createtime for 10) >= '" + begin_date.trim() + "'";
	       if (!end_date.trim().equals("")) otherSQL += " and substring(t.createtime for 10) <= '" + end_date.trim() + "'";
              String orderField = "t.taskid desc";
              int pageSize = 10;
            int pageno=1;
               String page2=request.getParameter("mgh");
              		if(page2==null||page2==""){
              				pageno=1;
              				}
              			else{
              					pageno=Integer.parseInt(page2);
              				}
              int pageNo = ParamUtils.getIntParameter(request,"page",pageno);
              	             String pageno1 = String.valueOf(pageNo); 
							session.setAttribute("pageno1",pageno1);
              list = taskMgr.get(otherSQL,orderField,pageNo,pageSize);
              int total = taskMgr.getTotal(); 
              boolean b=(total % pageSize ==0);
              int pageCount=b?(total/pageSize):(total/pageSize +1);
              if(pageNo>pageCount){
              	pageNo=pageCount;
              }
              if (list != null && list.size() > 0) {
               	String bgColor[] = {"#EDEDF0","#D7D7DB"};
              	//String bgColor[] = { "#EDEDF0", "#D7D7DB" };
              	for(int i=0;i<list.size();i++) {
              		Task item = (Task)list.get(i);
              	
              		Calendar cal = Calendar.getInstance();
              		cal.setTime(item.getCreatetime());
              		cal.add(Calendar.MONTH,-1);
              	
              		
              	
              %>
            	<tr align="center" bgcolor="<%=bgColor[i%2]%>" onMouseOver="this.style.background='#efefef'" onMouseOut="this.style.background='<%=bgColor[i%2]%>'">
                <td height="24">
                  <%=item.getCusname()%>
                </td>
               
                <td><%=item.getLinkman()%></td>
              
                 <td><%=item.getContract().getTechmanager_name()%></td>
                 <td><%=item.getEngineername()%></td>
                 <td align="right"><%=FormatNum.formatCurrencycn(item.getTripfee())%></td>
                 <td><%=item.getBegindate()%></td>
                <td><%=item.getEnddate()%></td>
                
               <td>
     			<span onclick="clk_task_select('<%=item.getId()%>','<%=item.getEngineerid()%>','<%=item.getEngineername()%>','<%=item.getCusname()%>');" style="cursor:hand;text-decoration: underline;">选择</span>
    			</td>
				 </tr>
              <%}%>
            </table>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/page_img/page_bk.gif">
              <tr height="32" align="center" valign="bottom"> 
                <td width="5%">
                 
                </td>
                <td height="35" align="right" style="padding-right:10px;" valign="bottom" id="pannelPageInfo">&nbsp;</td>
              </tr>
            </table>
            <script language="javascript">
            pannelPageInfo.innerHTML = getPageInfo(<%=total%>,<%=pageSize%>,<%=pageNo%>,5,'images/page_img','pageForm');
            </script>
            <%}else{%>
            </table>
            <table width="95%" border="0" cellpadding="4" cellspacing="1" bgcolor="#FFFFFF">
              <tr> 
                <td height="60" align="center">目前没有任何工单信息!</td>
              </tr>
            </table>
            <%}%>
         </form>
         </td>
         </tr>
         </table>
         
<script language="javascript">
	htmlBeginTime.innerHTML = showCalenderInput("begin_date","pageForm","<%=begin_date%>",1);
	htmlEndTime.innerHTML = showCalenderInput("end_date","pageForm","<%=end_date%>",1);
</script>
</body>
</html>